const app = getApp();
var api = require('../../../../api.js');

Page({
  data: {
    list:[],
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      id: options.id
    })
  },
  onReady: function () {
  
  },
  onShow: function () {
    this.getNumber();
    this.getRecord();
  },
  onHide: function () {
  
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
    wx.hideShareMenu();
  },
  // 获取可转赠会员卡数量
  getNumber: function () {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    // var id = that.data.id;
    // console.log(id);
    wx.request({
      url:api.card.number,
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        id: that.data.id
      },
      success: function (e) {
        // console.log(e);
        var list = e.data.data;
        // console.log(list);
        if (e.data.code == 0) {
          that.setData({
            number: list
          })
        } else if (e.data.code == 1) {
          wx.navigateTo({
            url: '/pages/login/login'
          })
        } else {
          wx.navigateTo({
            url: '/pages/grant/grant'
          })
        }
        // console.log(that.data);
      }
    });
  },
  // 领取列表
  getRecord: function () {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    wx.request({
      url:api.card.record,
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
      },
      success: function (e) {
        // console.log(e);
        var list = e.data.data;
        // console.log(list);
        if (e.data.code == 0) {
          that.setData({
            list: list
          })
        } else if (e.data.code == 1) {
          wx.navigateTo({
            url: '/pages/login/login'
          })
        } else {
          wx.navigateTo({
            url: '/pages/grant/grant'
          })
        }
      }
    });
  },
})